﻿using MiniFox.Resources;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sys.Core.Models.Dto
{
    public class SequenceSetDto
    {
        [Key]
        [StringLength(50, ErrorMessageResourceType = typeof(CommonMessages), ErrorMessageResourceName = "MSG_CommonStringLength")]
        public string Name { get; set; }

        [Display(Name = "前缀", ShortName = "前缀")]
        [Required(ErrorMessageResourceType = typeof(CommonMessages), ErrorMessageResourceName = "MSG_CommonRequired")]
        [StringLength(5, ErrorMessageResourceType = typeof(CommonMessages), ErrorMessageResourceName = "MSG_CommonStringLength")]
        public string Prefix { get; set; } = string.Empty;

        [Display(Name = "后缀", ShortName = "后缀")]
        public string? Suffix { get; set; }

        [Display(Name = "匹配格式", ShortName = "匹配格式")]
        [Required(ErrorMessageResourceType = typeof(CommonMessages), ErrorMessageResourceName = "MSG_CommonRequired")]
        [StringLength(20, ErrorMessageResourceType = typeof(CommonMessages), ErrorMessageResourceName = "MSG_CommonStringLength")]
        public string Pattern { get; set; } = "yyyyMMddHHmmss";

        [Display(Name = "是否基于UTC时间", ShortName = "是否基于UTC时间")]
        [Required(ErrorMessageResourceType = typeof(CommonMessages), ErrorMessageResourceName = "MSG_CommonRequired")]
        public bool BaseOnUtc { get; set; } = false;

        [Display(Name = "后缀长度", ShortName = "后缀长度")]
        [Required(ErrorMessageResourceType = typeof(CommonMessages), ErrorMessageResourceName = "MSG_CommonRequired")]
        public byte Length { get; set; } = 4;

        [Display(Name = "序列描述", ShortName = "序列描述")]
        public string? Description { get; set; }

        [JsonIgnore]
        public int MaxVal
        {
            get
            {
                int maxVal = 0;
                int len = this.Length;
                while (len-- >= 0)
                {
                    maxVal += 9 * (int)Math.Pow(10, len);
                }
                return maxVal;
            }
        }
    }
}
